<?php

session_start();

header('Pragma: no-cache');
header('Cache-Control: no-cache');
header('Content-Type: text/plain');
header('Content-Disposition: text/plain');

set_error_handler("errorHandler");

$pass = '0';
$contact_id = '';

$mysqli = new mysqli("localhost", "root", "", "ravebiz", "3306");

if ($mysqli)
{
	$query = "call login('".$_GET['u']."','".$_GET['p']."');";
	$result = $mysqli->query($query);

	if ($result)
	{
	    $row = $result->fetch_assoc();
		$contact_id = $row['contacts_id'];
		if ($contact_id!='') 
		{
			$pass = '1';
			$_SESSION['contactId'] = $contact_id;
		}
		$result->close();
	}
	
	$mysqli->close();
}

echo $pass."\n";
echo $contact_id;

function errorHandler($errno, $errstr, $errfile, $errline)
{
    printf("<Error>Connect failed: %s.</Error>\n", mysqli_connect_error());
}

?>
